<template>
	<a-card :bordered="false" :body-style="{ 'padding-bottom': '0px' }" class="mb-2">
		<a-form ref="formRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
			<a-row :gutter="24">
				<a-col :span="6">
					<a-form-item label="卡号" name="cardCode">
						<a-input v-model:value="searchFormState.cardCode" allow-clear></a-input>
					</a-form-item>
				</a-col>
				<a-col :span="6">
					<a-button type="primary" html-type="submit" @click="table.refresh()">查询</a-button>
					<a-button style="margin: 0 8px" @click="() => formRef.resetFields()">重置</a-button>
				</a-col>
			</a-row>
		</a-form>
	</a-card>
	<a-card :bordered="false">
		<s-table
			ref="table"
			:columns="columns"
			:data="loadData"
			:alert="options.alert.show"
			bordered
			:row-key="(record) => record.id"
			:tool-config="toolConfig"
			:row-selection="options.rowSelection"
		>
			<template #operator class="table-operator">
				<a-space>
					<a-button type="primary" @click="form.onOpen()">
						导出
					</a-button>
				</a-space>
			</template>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'actionType'">
					<a-tag v-if="record.actionType === 'ADD'" color="green">
						{{ $TOOL.dictTypeData('ADJUST_ACCOUNT_ACTION', record.actionType) }}
					</a-tag>
					<a-tag v-if="record.actionType === 'MINUS'" color="red">
						{{ $TOOL.dictTypeData('ADJUST_ACCOUNT_ACTION', record.actionType) }}
					</a-tag>
				</template>
			</template>
		</s-table>
	</a-card>
</template>

<script setup name="crmMemberAdjustAccount">
	import { message } from 'ant-design-vue'
	import crmApi from '@/api/crm/crmApi'
	import tool from '@/utils/tool'
	let searchFormState = reactive({})
	const formRef = ref()
	const table = ref(null)
	let form = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: true, striped: true }
	const columns = [
		{
			title: '卡号',
			dataIndex: 'cardCode',
			width: 160
		},
		{
			title: '操作门店',
			dataIndex: 'storeName'
		},
		{
			title: '调整金额',
			dataIndex: 'amount',
			width: 80,
			align: 'center'
		},
		{
			title: '结存金额',
			dataIndex: 'currentAmount',
			width: 80,
			align: 'center'
		},
		{
			title: '储值本金',
			dataIndex: 'amountRecharge',
			width: 80,
			align: 'center'
		},
		{
			title: '储值赠送',
			dataIndex: 'amountPresent',
			width: 80,
			align: 'center'
		},
		{
			title: '调账类型',
			dataIndex: 'actionType',
			width: 80,
			align: 'center'
		},
		{
			title: '备注',
			dataIndex: 'note',
			width: 200,
			ellipsis: true
		},
		{
			title: '创建时间',
			dataIndex: 'createdTime',
			ellipsis: true,
			sorter: true,
			width: 160,
			align: 'center'
		}
	]
	let selectedRowKeys = ref([])
	// 列表选择配置
	const options = {
		alert: {
			show: false,
			clear: () => {
				selectedRowKeys = ref([])
			}
		},
		rowSelection: {
			onChange: (selectedRowKey, selectedRows) => {
				selectedRowKeys.value = selectedRowKey
			}
		}
	}
	// 列表数据
	const loadData = (parameter) => {
		return crmApi.memberAdjustAccountPage(Object.assign(parameter, searchFormState)).then((res) => {
			return res
		})
	}

</script>

<style scoped>

</style>
